﻿using System;
using System.Data;
using System.Text;
using System.Data.SqlClient;
using Maticsoft.DBUtility;//Please add references
namespace ChinaSoft.DAL
{
	/// <summary>
	/// 数据访问类:DAL_tb_MidSoft_RtxMessage
	/// </summary>
	public partial class DAL_tb_MidSoft_RtxMessage
	{
		public DAL_tb_MidSoft_RtxMessage()
		{}
		#region  Method

		/// <summary>
		/// 得到最大ID
		/// </summary>
		public int GetMaxId()
		{
		return DbHelperSQL.GetMaxID("RtxMessageId", "tb_MidSoft_RtxMessage"); 
		}

		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(int RtxMessageId)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from tb_MidSoft_RtxMessage");
			strSql.Append(" where RtxMessageId=@RtxMessageId");
			SqlParameter[] parameters = {
					new SqlParameter("@RtxMessageId", SqlDbType.Int,4)
};
			parameters[0].Value = RtxMessageId;

			return DbHelperSQL.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public int Add(ChinaSoft.Model.Model_tb_MidSoft_RtxMessage model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into tb_MidSoft_RtxMessage(");
			strSql.Append("ProjectInfoId,ReceiveUserId,ReceiveUserName,MessageContent,CreateTime,SendUserId,SendUserName,RtxMessageState)");
			strSql.Append(" values (");
			strSql.Append("@ProjectInfoId,@ReceiveUserId,@ReceiveUserName,@MessageContent,@CreateTime,@SendUserId,@SendUserName,@RtxMessageState)");
			strSql.Append(";select @@IDENTITY");
			SqlParameter[] parameters = {
					new SqlParameter("@ProjectInfoId", SqlDbType.Int,4),
					new SqlParameter("@ReceiveUserId", SqlDbType.Int,4),
					new SqlParameter("@ReceiveUserName", SqlDbType.NVarChar,10),
					new SqlParameter("@MessageContent", SqlDbType.NVarChar,500),
					new SqlParameter("@CreateTime", SqlDbType.DateTime),
					new SqlParameter("@SendUserId", SqlDbType.Int,4),
					new SqlParameter("@SendUserName", SqlDbType.NVarChar,10),
					new SqlParameter("@RtxMessageState", SqlDbType.NVarChar,1)};
			parameters[0].Value = model.ProjectInfoId;
			parameters[1].Value = model.ReceiveUserId;
			parameters[2].Value = model.ReceiveUserName;
			parameters[3].Value = model.MessageContent;
			parameters[4].Value = model.CreateTime;
			parameters[5].Value = model.SendUserId;
			parameters[6].Value = model.SendUserName;
			parameters[7].Value = model.RtxMessageState;

			object obj = DbHelperSQL.GetSingle(strSql.ToString(),parameters);
			if (obj == null)
			{
				return 0;
			}
			else
			{
				return Convert.ToInt32(obj);
			}
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public bool Update(ChinaSoft.Model.Model_tb_MidSoft_RtxMessage model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update tb_MidSoft_RtxMessage set ");
			strSql.Append("ProjectInfoId=@ProjectInfoId,");
			strSql.Append("ReceiveUserId=@ReceiveUserId,");
			strSql.Append("ReceiveUserName=@ReceiveUserName,");
			strSql.Append("MessageContent=@MessageContent,");
			strSql.Append("CreateTime=@CreateTime,");
			strSql.Append("SendUserId=@SendUserId,");
			strSql.Append("SendUserName=@SendUserName,");
			strSql.Append("RtxMessageState=@RtxMessageState");
			strSql.Append(" where RtxMessageId=@RtxMessageId");
			SqlParameter[] parameters = {
					new SqlParameter("@ProjectInfoId", SqlDbType.Int,4),
					new SqlParameter("@ReceiveUserId", SqlDbType.Int,4),
					new SqlParameter("@ReceiveUserName", SqlDbType.NVarChar,10),
					new SqlParameter("@MessageContent", SqlDbType.NVarChar,500),
					new SqlParameter("@CreateTime", SqlDbType.DateTime),
					new SqlParameter("@SendUserId", SqlDbType.Int,4),
					new SqlParameter("@SendUserName", SqlDbType.NVarChar,10),
					new SqlParameter("@RtxMessageState", SqlDbType.NVarChar,1),
					new SqlParameter("@RtxMessageId", SqlDbType.Int,4)};
			parameters[0].Value = model.ProjectInfoId;
			parameters[1].Value = model.ReceiveUserId;
			parameters[2].Value = model.ReceiveUserName;
			parameters[3].Value = model.MessageContent;
			parameters[4].Value = model.CreateTime;
			parameters[5].Value = model.SendUserId;
			parameters[6].Value = model.SendUserName;
			parameters[7].Value = model.RtxMessageState;
			parameters[8].Value = model.RtxMessageId;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public bool Delete(int RtxMessageId)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from tb_MidSoft_RtxMessage ");
			strSql.Append(" where RtxMessageId=@RtxMessageId");
			SqlParameter[] parameters = {
					new SqlParameter("@RtxMessageId", SqlDbType.Int,4)
};
			parameters[0].Value = RtxMessageId;

			int rows=DbHelperSQL.ExecuteSql(strSql.ToString(),parameters);
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}
		/// <summary>
		/// 批量删除数据
		/// </summary>
		public bool DeleteList(string RtxMessageIdlist )
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete from tb_MidSoft_RtxMessage ");
			strSql.Append(" where RtxMessageId in ("+RtxMessageIdlist + ")  ");
			int rows=DbHelperSQL.ExecuteSql(strSql.ToString());
			if (rows > 0)
			{
				return true;
			}
			else
			{
				return false;
			}
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public ChinaSoft.Model.Model_tb_MidSoft_RtxMessage GetModel(int RtxMessageId)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select  top 1 RtxMessageId,ProjectInfoId,ReceiveUserId,ReceiveUserName,MessageContent,CreateTime,SendUserId,SendUserName,RtxMessageState from tb_MidSoft_RtxMessage ");
			strSql.Append(" where RtxMessageId=@RtxMessageId");
			SqlParameter[] parameters = {
					new SqlParameter("@RtxMessageId", SqlDbType.Int,4)
};
			parameters[0].Value = RtxMessageId;

			ChinaSoft.Model.Model_tb_MidSoft_RtxMessage model=new ChinaSoft.Model.Model_tb_MidSoft_RtxMessage();
			DataSet ds=DbHelperSQL.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				if(ds.Tables[0].Rows[0]["RtxMessageId"]!=null && ds.Tables[0].Rows[0]["RtxMessageId"].ToString()!="")
				{
					model.RtxMessageId=int.Parse(ds.Tables[0].Rows[0]["RtxMessageId"].ToString());
				}
				if(ds.Tables[0].Rows[0]["ProjectInfoId"]!=null && ds.Tables[0].Rows[0]["ProjectInfoId"].ToString()!="")
				{
					model.ProjectInfoId=int.Parse(ds.Tables[0].Rows[0]["ProjectInfoId"].ToString());
				}
				if(ds.Tables[0].Rows[0]["ReceiveUserId"]!=null && ds.Tables[0].Rows[0]["ReceiveUserId"].ToString()!="")
				{
					model.ReceiveUserId=int.Parse(ds.Tables[0].Rows[0]["ReceiveUserId"].ToString());
				}
				if(ds.Tables[0].Rows[0]["ReceiveUserName"]!=null && ds.Tables[0].Rows[0]["ReceiveUserName"].ToString()!="")
				{
					model.ReceiveUserName=ds.Tables[0].Rows[0]["ReceiveUserName"].ToString();
				}
				if(ds.Tables[0].Rows[0]["MessageContent"]!=null && ds.Tables[0].Rows[0]["MessageContent"].ToString()!="")
				{
					model.MessageContent=ds.Tables[0].Rows[0]["MessageContent"].ToString();
				}
				if(ds.Tables[0].Rows[0]["CreateTime"]!=null && ds.Tables[0].Rows[0]["CreateTime"].ToString()!="")
				{
					model.CreateTime=DateTime.Parse(ds.Tables[0].Rows[0]["CreateTime"].ToString());
				}
				if(ds.Tables[0].Rows[0]["SendUserId"]!=null && ds.Tables[0].Rows[0]["SendUserId"].ToString()!="")
				{
					model.SendUserId=int.Parse(ds.Tables[0].Rows[0]["SendUserId"].ToString());
				}
				if(ds.Tables[0].Rows[0]["SendUserName"]!=null && ds.Tables[0].Rows[0]["SendUserName"].ToString()!="")
				{
					model.SendUserName=ds.Tables[0].Rows[0]["SendUserName"].ToString();
				}
				if(ds.Tables[0].Rows[0]["RtxMessageState"]!=null && ds.Tables[0].Rows[0]["RtxMessageState"].ToString()!="")
				{
					model.RtxMessageState=ds.Tables[0].Rows[0]["RtxMessageState"].ToString();
				}
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select RtxMessageId,ProjectInfoId,ReceiveUserId,ReceiveUserName,MessageContent,CreateTime,SendUserId,SendUserName,RtxMessageState ");
			strSql.Append(" FROM tb_MidSoft_RtxMessage ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return DbHelperSQL.Query(strSql.ToString());
		}

		/// <summary>
		/// 获得前几行数据
		/// </summary>
		public DataSet GetList(int Top,string strWhere,string filedOrder)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select ");
			if(Top>0)
			{
				strSql.Append(" top "+Top.ToString());
			}
			strSql.Append(" RtxMessageId,ProjectInfoId,ReceiveUserId,ReceiveUserName,MessageContent,CreateTime,SendUserId,SendUserName,RtxMessageState ");
			strSql.Append(" FROM tb_MidSoft_RtxMessage ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			strSql.Append(" order by " + filedOrder);
			return DbHelperSQL.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			SqlParameter[] parameters = {
					new SqlParameter("@tblName", SqlDbType.VarChar, 255),
					new SqlParameter("@fldName", SqlDbType.VarChar, 255),
					new SqlParameter("@PageSize", SqlDbType.Int),
					new SqlParameter("@PageIndex", SqlDbType.Int),
					new SqlParameter("@IsReCount", SqlDbType.Bit),
					new SqlParameter("@OrderType", SqlDbType.Bit),
					new SqlParameter("@strWhere", SqlDbType.VarChar,1000),
					};
			parameters[0].Value = "tb_MidSoft_RtxMessage";
			parameters[1].Value = "RtxMessageId";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return DbHelperSQL.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  Method
	}
}

